package com.groupseven.happycampus.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.groupseven.happycampus.common.pojo.Fixture;
import com.groupseven.happycampus.common.result.LayuiPageVo;
import com.groupseven.happycampus.mapper.FixtureMapper;
import com.groupseven.happycampus.service.FixtureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("/fixtureService")
public class FixtureServiceImpl implements FixtureService {


    @Autowired
    public FixtureMapper fixtureMapper;

    /**
     *
     * @param params
     * @return
     */
    @Override
    public LayuiPageVo<Fixture> selectFixture(Map<String, Object> params) {
        Integer page = Integer.parseInt(params.get("page")+"");
        Integer limit = Integer.parseInt(params.get("limit")+"");
        PageHelper.startPage(page,limit);

        List<Fixture> fixtureList = fixtureMapper.selectFixture(params);

        PageInfo<Fixture> fixturePageInfo = new PageInfo<>(fixtureList);

        LayuiPageVo<Fixture> fixtureLayuiPageVo = new LayuiPageVo<>();
        fixtureLayuiPageVo.setCode(0);
        fixtureLayuiPageVo.setMsg("分页列表数据");
        fixtureLayuiPageVo.setCount((int) fixturePageInfo.getTotal());
        fixtureLayuiPageVo.setData(fixturePageInfo.getList());
        return fixtureLayuiPageVo;
    }

    /**
     *
     * @param fixture
     * @return
     */

    @Override
    public int addFixture(Fixture fixture) {
        int i = fixtureMapper.addFixture(fixture);
        return i;
    }

    /**
     *
     * @param id
     * @return
     */

    @Override
    public int deleteFixtureById(Integer id) {
        return fixtureMapper.deleteFixtureById(id);
    }

    /**
     *
     * @param ids
     * @return
     */

    @Override
    public int deleteFixtureByIds(String ids) {
        String[] arrId = ids.split(",");
        return fixtureMapper.deleteFixtureByIds(arrId);
    }

    /**
     *
     * @param fixture
     * @return
     */

    @Override
    public int updateFixture(Fixture fixture) {
        return fixtureMapper.updateFixture(fixture);
    }
}
